import IconUI from "./icon-ui.js";

const UI = new IconUI();

// 浏览器扩展(包含图标、工具提示、徽章和弹出内容）单击事件
chrome.action.onClicked.addListener((currentTab) => {
  console.log("切换隐藏广告扩展开关:", currentTab);
  UI.toggleHideAdSwitch(currentTab);
});

// 切换页面时触发--页面从开启了HideAd扩展的网站切换到未开启HideAd的网站,需要将HideAd插件设置为禁用状态
chrome.tabs.onActivated.addListener(async (newTab) => {
  chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
    // console.log(tabs[0]);
    console.log("标签页切换：", tabs[0]);
    UI.initPageStatus(tabs[0]);
  });
});

// 接收内容脚本发送过来的消息
chrome.runtime.onMessage.addListener((response, sender) => {
  console.log("后台接收来自网页的消息", response, sender);
});
